package net.chenlin.dp.modules.business.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.chenlin.dp.common.entity.R;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Yangsm
 * @ClassName: SendMessageController
 * @Description: TODO
 * @date 2023年03月27日 20:34
 */
@Slf4j
@RestController
@RequestMapping("/sendMessage")
@Api(tags = "发送消息")
public class SendMessageController {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ApiOperation(value = "测试")
    public R sendMessage() throws IOException {
        OutputStream outputStream =null;
        Socket socket = null;
        ServerSocket serviceSocket = new ServerSocket(8086);
        //获取socket。这个方法是阻塞式的
        socket = serviceSocket.accept();
        outputStream = socket.getOutputStream();
        outputStream.write("收到".getBytes());
        return R.ok("发送成功");
    }
}
